package com.ruoyi.system.service.impl.basic;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.dto.WareDto;
import com.ruoyi.system.domain.vo.WareVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.basic.BasicWarehousesMapper;
import com.ruoyi.system.domain.db.basic.BasicWarehouses;
import com.ruoyi.system.service.IBasicWarehousesService;

/**
 * 仓库管理Service业务层处理
 * 
 * @author sen
 * @date 2023-07-25
 */
@Service
public class BasicWarehousesServiceImpl implements IBasicWarehousesService 
{
    @Autowired
    private BasicWarehousesMapper basicWarehousesMapper;

    /**
     * 查询仓库管理
     * 
     * @param warehouseId 仓库管理主键
     * @return 仓库管理
     */
    @Override
    public WareDto selectBasicWarehousesByWarehouseId(Long warehouseId)
    {
        return basicWarehousesMapper.selectBasicWarehousesByWarehouseId(warehouseId);
    }

    /**
     * 查询仓库管理列表
     *
     * @param basicWarehouses 仓库管理
     * @return 仓库管理
     */
    public List<WareDto> selectWareDtoList(BasicWarehouses basicWarehouses)
    {
        return basicWarehousesMapper.selectWareDtoList(basicWarehouses);
    }

    @Override
    public List<BasicWarehouses> selectBasicWarehousesList(BasicWarehouses basicWarehouses)
    {
        return basicWarehousesMapper.selectBasicWarehouses(basicWarehouses);
    }

    /**
     * 新增仓库管理
     * 
     * @param basicWarehouses 仓库管理
     * @return 结果
     */
    @Override
    public int insertBasicWarehouses(BasicWarehouses basicWarehouses)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Date nowDate = DateUtils.getNowDate();
        basicWarehouses.setCreateTime(nowDate);
        basicWarehouses.setUpdateTime(nowDate);
        basicWarehouses.setUpdateBy(loginUser.getUserId());
        basicWarehouses.setCreateBy(loginUser.getUserId());
        return basicWarehousesMapper.insertBasicWarehouses(basicWarehouses);
    }



    /**
     * 修改仓库管理
     * 
     * @param basicWarehouses 仓库管理
     * @return 结果
     */
    @Override
    public int updateBasicWarehouses(BasicWarehouses basicWarehouses)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Date nowDate = DateUtils.getNowDate();
        basicWarehouses.setUpdateTime(nowDate);
        basicWarehouses.setUpdateBy(loginUser.getUserId());
        return basicWarehousesMapper.updateBasicWarehouses(basicWarehouses);
    }

    /**
     * 批量删除仓库管理
     * 
     * @param warehouseIds 需要删除的仓库管理主键
     * @return 结果
     */
    @Override
    public int deleteBasicWarehousesByWarehouseIds(Long[] warehouseIds)
    {
        return basicWarehousesMapper.deleteBasicWarehousesByWarehouseIds(warehouseIds);
    }

    /**
     * 删除仓库管理信息
     * 
     * @param warehouseId 仓库管理主键
     * @return 结果
     */
    @Override
    public int deleteBasicWarehousesByWarehouseId(Long warehouseId)
    {
        return basicWarehousesMapper.deleteBasicWarehousesByWarehouseId(warehouseId);
    }


    public WareVo DtoConvertToVo(WareDto wareDto)
    {
        WareVo wareVo = new WareVo();
        wareVo.setWarehouseId(wareDto.getWarehouseId());
        wareVo.setManagerId(wareDto.getManager().getUserId());
        wareVo.setManagerName(wareDto.getManager().getUserName());
        wareVo.setManagerPhoneNumber(wareDto.getManager().getPhonenumber());
        wareVo.setWarehouseName(wareDto.getWarehouseName());
        wareVo.setAddress(wareDto.getAddress());
        wareVo.setDistrict(wareDto.getDistrict());
        wareVo.setTown(wareDto.getTown());
        wareVo.setLevel(wareDto.getLevel());
        wareVo.setMonthRental(wareDto.getMonthRental());
        wareVo.setCreateTime(wareDto.getCreateTime());
        wareVo.setUpdateTime(wareDto.getCreateTime());
        return wareVo;
    }
}
